<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/views/common/taglibs.jsp" %>

<!DOCTYPE>
<html>
<head>
	<!-- 引入通用js、css文件(xiaogq) -->
	<meta name="decorator" content="default"/>
	<link rel="stylesheet" type="text/css" href="${ctx}/css/common/operation/sys_operation.css"/>
	<style type="text/css">
		.table-base{
			border: 1px solid #d9d9d9;
			border-collapse: collapse;
			empty-cells: show;
			margin: 5px auto;
			width: 98%;
		}
		.table-base tr{
			width:100%;
		}
		.table-base tr td{
			border:1px solid #d9d9d9;
			height:32px;
			text-align:center;
			line-height:32px;
			border-collapse: collapse;
			empty-cells: show;
			color:#647487;
		}
		.table-base tr td a{
			color:#647487;
			cursor:pointer;
		}
		.table-base tr td a:hover{
			color:#3195d4;
		}
		.app_tr{
			background: -webkit-linear-gradient(top,#ffffff,#fcfcfc);
			background: -moz-linear-gradient(top,#ffffff,#fcfcfc);
			background: -o-linear-gradient(top,#ffffff,#fcfcfc);
			background: linear-gradient(top,#ffffff,#fcfcfc);
			filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0, startColorstr=#ffffff, endColorstr=#fcfcfc);/*IE<9>*/
			-ms-filter: "progid:DXImageTransform.Microsoft.gradient (GradientType=0, startColorstr=#ffffff, endColorstr=#fcfcfc)";/*IE8+*/
		}
		.app_odd{
			background: #ffffff;
		}
		.app_odd:hover{
			background: #f4f4f4;
		}
		.app_eve{
			background: #fcfcfc;
		}
		.app_eve:hover{
			background: #f4f4f4;
		}
	</style>
	<script type="text/javascript">
		$(document).ready(function(){
			//标记改动过的行
			$(".authCheck").bind("change",function(){
				$(this).parents("tr").attr("changed",true);
			});
		});

		//保存
		function saveControlAuth(){
			var authArr = new Array();
			$("#controledTab tr[changed]").each(function(){
				var rowAuth = $(this).attr("rid");
				$(this).find(".authCheck").each(function(){
					if($(this).is(':checked')){
						rowAuth += "|1"
					}else{
						rowAuth += "|0"
					}
				});
				authArr.push(rowAuth);
			});
			if(authArr.length > 0){
				$.ajax({
					url: '${ctx}/FieldRecord/saveFieldControl.do?entityId=${entityId}&fieldId=${fieldId}&fieldName=${fieldName}&authArr='+authArr,
					type: 'POST',
					success: function(){
						parent.closeTab(1);
					},
					error: function() {
						alert("操作失败");
					}
				});
			}else{
				parent.closeTab(1);
			}
		}
	</script>
</head>
<body>
	<!-- 加载列表操作 -->
	<div id="buttonArray" class="button_list">
		<a href="javascript:;" onclick="saveControlAuth()">
			<span class="span_button">
				<span><img src="${ctx}/image/common/operation/oper_SAVE.png"></span>
				<span name="buTitle">保存</span>
			</span>
		</a>
		<a href="javascript:;" onclick="javascript:parent.closeTab();">
			<span class="span_button">
				<span ><img src="${ctx}/image/common/operation/oper_CANCEL.png"></span>
				<span name="buTitle" title="">取消</span>
			</span>
		</a>
	</div>

	<div style="height: 90%;overflow: auto; width: 1000px;" >
		<table id="controledTab" class="table-base" border="1" >
			<tr class="app_tr">
				<td>角色</td>
				<td>负责员工（不可编辑）</td>
				<td>负责员工（不可查看）</td>
			</tr>
			<c:if test="${ !empty authList}">
				<c:forEach var="item" items="${authList}" varStatus="status">

					<tr rid="${item.roleId }"
						<c:if test="${status.index%2==0 }">class="app_eve"</c:if>
						<c:if test="${status.index%2!=0 }">class="app_odd"</c:if> >
						<td>${item.roleName }</td>
						<td><input class="authCheck" type="checkbox" <c:if test="${ item.forbidEditCharge }">checked="checked"</c:if> /> </td>
						<td><input class="authCheck" type="checkbox" <c:if test="${ item.forbidViewCharge }">checked="checked"</c:if> /> </td>
					</tr>
				</c:forEach>
			</c:if>
		</table>
		<input type="hidden" id="fieldId" value="${fieldId}" />
		<input type="hidden" id="entityId" value="${entityId}" />
	</div>
</body>
</html>
